<?php

/**
 * session actions.
 *
 * @package    ldaad
 * @subpackage session
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 2288 2006-10-02 15:22:13Z fabien $
 */
class sessionActions extends autosessionActions
{

  public function executeBackToConference()
  {
    //this part is highly ineffective
    $session = SessionPeer::retrieveByPK($this->getRequestParameter('id'));

    $this->redirect('conference/edit?id='.$session->getConferenceId());
    #$this->redirect('session/create?conference_id='.$this->getRequestParameter('id'));
  }
  
  public function executeBackToConferenceList()
  {
    $this->redirect('conference/list');
  }
  
  public function executeDeleteToConference()
  {

    $session = SessionPeer::retrieveByPK($this->getRequestParameter('id'));
    
    $this->forward404Unless($session);
    
    $tempConferenceId = $session->getConferenceId();
    
    $session->delete();
    
    $this->redirect('conference/edit?id='.$tempConferenceId);
    
  }
  
  
  
  //public registration
  
    public function executeAvailableSessions()
  {
    /*
    Step to list availablesessions which correspond to selected conference
    1. Get conference Id from user session
    2. create criteria
    3. get from database 
    4. put into $this
    5. find out the clashing id
    6. put the clashing id in this
    */
    $conferenceID = $this->getUser()->getAttribute('conferenceIDSession');

    $c = new Criteria();
    $c-> add(SessionPeer::CONFERENCE_ID, $conferenceID);
    $c-> addAscendingOrderByColumn(SessionPeer::TIME_START);
    $sessions = SessionPeer::doSelect($c);
    $this->sessions = $sessions;
    
    //preventive-validation to ensure overlapped session will not be register-able
    $forbiddenIDArray = array ();
    
    if ($this->getUser()->hasAttribute('sessionIDArraySession'))
    {
      $sessionIDArray = $this->getUser()->getAttribute('sessionIDArraySession');
      
      $forbiddenIDArray = Session::getClashedSessionIDs($sessionIDArray);
      
      $this->getUser()->setAttribute('forbiddenSessionIDArraySession' , $forbiddenIDArray);
    }
    
  }
  
  

  
  public function executeRegisterIndividualSession()
  {
    //CFR put session id in an array... easier
    /*
    Step to register individual session
    1. get session id from request parameter
    2. put sessionid in user session
    3. redirect to session/availableSessions
    */
    $registeredSessionID = $this->getRequestParameter('id');

    $this->getUser()->setAttribute('sessionIDSession'.$registeredSessionID, $registeredSessionID);
    
    if (!$this->getUser()->hasAttribute('sessionIDArraySession'))
    {
      $registeredSessionIDArray = array ( );
    }
    else
    {
      $registeredSessionIDArray = $this->getUser()->getAttribute('sessionIDArraySession');
    }
    
    $registeredSessionIDArray[] = $registeredSessionID;

    $this->getUser()->setAttribute('sessionIDArraySession', $registeredSessionIDArray);
    

    return $this->redirect('session/availableSessions');
  }
  
  public function executeDeregisterIndividualSession()
  {
    /*
    Step to deregister individual session
    1. get session id from getrequest parameter
    2. remove session id from user session
    3. redirect to session/availablesession
    */
    $deregisteredSessionID = $this->getRequestParameter('id');
    
    $this->getUser()->getAttributeHolder()->remove('sessionIDSession'.$deregisteredSessionID);

    $registeredSessionIDArray = $this->getUser()->getAttribute('sessionIDArraySession');

    $registeredSessionIDArray = myTools::array_remove_value($registeredSessionIDArray, $deregisteredSessionID);
    
    $this->getUser()->setAttribute('sessionIDArraySession', $registeredSessionIDArray);
    
    return $this->redirect('session/availableSessions');
  }
  
  public function executeConfirmedSessions()
  {
    /*
    Sessions selection are confirmed
    1. go to publicRegistrations 
    */
    return $this->redirect('publicRegistration/startSpecialEvents');  
    //return $this->redirect('specialEvent/availableSpecialEvents');  
  }
}



